<template>
  <div class="select-none">
    <div class="absolute inset-y-0 left-0 right-0 bg-gradient-to-t from-gray-800 to-gray-600 opacity-70 z-0"></div>
    <div class="tenant " >
      <!--  租户选择 -->
      <tenant/>
    </div>
    <!--<div class="mini_qr">-->
    <!--  &lt;!&ndash; 扫码体验移动端 &ndash;&gt;-->
    <!--  <img :src="!themeConfig.miniQr ?  miniQr:baseURL +  themeConfig.miniQr"/>-->
    <!--  <p>{{ t('scan.wechatApp') }}</p>-->
    <!--</div>-->
<!--    <img :src="bg" class="wave"/>-->
  <img :src="line" class="wave z-1"/>
  <div class="w-full h-full z-4 wave logBox"></div>
  <div class="flex-c absolute right-5 top-3"></div>
    <div class="login-container  z-20 relative">
      <carousel @changeBackgroundColor="changeBackgroundColor"/>
<!--      <div class="img">-->
<!--        <img-->
<!--            :src="!themeConfig.background ?  illustration:baseURL + themeConfig.background"/>-->


<!--      </div>-->
      <div class="login-box ">
        <div class="login-form">

          <div class="flex  justify-center self-center">
            <div class="p-12 mx-auto bg-white rounded-3xl text-black w-96">
              <!-- <div class=" text-6xl font-semibold">{{ getThemeConfig.globalTitle }}</div> -->
              <div  class="flex text-6xl font-semibold">
                <img class="semibold-icon" src="/@/assets/MF-logo.png"/>
                <span>{{ 'MFLers Login' }}</span>
              </div>
              <div class="Elegant text-6x">Elegant Mexican Flooring Digital Platform</div>
              <div class="space-y-0">
                <register v-if="loginType === LoginTypeEnum.REGISTER" @change="changeLoginType"/>
                <password v-if="loginType === LoginTypeEnum.PASSWORD" @signInSuccess="signInSuccess"
                          @change="changeLoginType"/>
                <mobile v-if="loginType === LoginTypeEnum.MOBILE" @signInSuccess="signInSuccess"
                        @change="changeLoginType"/>
                <expire v-if="loginType === LoginTypeEnum.EXPIRE" :username="username" @change="changeLoginType"/>


                <div class="flex items-center justify-center space-x-2 my-5">
                  <span class="h-px w-16 bg-gray-100"></span>
                  <span class="text-gray-300 font-normal">or</span>
                  <span class="h-px w-16 bg-gray-100"></span>
                </div>
                <!--<social @signInSuccess="signInSuccess"/>-->
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts" name="loginIndex">
import {useThemeConfig} from '/@/stores/themeConfig';
import {NextLoading} from '/@/utils/loading';
import illustration from '/@/assets/login/login_bg.svg';
import bg from '/@/assets/login/bg.png';
import line from '/@/assets/login/space_line.png';
import {useI18n} from 'vue-i18n';
import {formatAxis} from '/@/utils/formatTime';
import {useMessage} from '/@/hooks/message';
import {Session} from '/@/utils/storage';
import {initBackEndControlRoutes} from '/@/router/backEnd';
import {LoginTypeEnum} from "/@/api/login";

// 引入组件
const Password = defineAsyncComponent(() => import('./component/password.vue'));
const Mobile = defineAsyncComponent(() => import('./component/mobile.vue'));
const Social = defineAsyncComponent(() => import('./component/social.vue'));
const Register = defineAsyncComponent(() => import('./component/register.vue'));
const Expire = defineAsyncComponent(() => import('./component/expire.vue'));
const Tenant = defineAsyncComponent(() => import('./component/tenant.vue'));
const carousel = defineAsyncComponent(() => import('./component/carousel.vue'));

// 定义变量内容
const storesThemeConfig = useThemeConfig();
const {themeConfig} = storeToRefs(storesThemeConfig);
const {t} = useI18n();
const route = useRoute();
const router = useRouter();

// 登录方式
const loginType = ref(LoginTypeEnum.PASSWORD)
// 用户名
const username = ref('')

// 修改登录类型
const changeLoginType = (type: LoginTypeEnum, name?: string) => {
  loginType.value = type
  if (name) {
    username.value = name
  }
}

// 获取布局配置信息
const getThemeConfig = computed(() => {
  return themeConfig.value;
});

// 登录成功后的跳转处理事件
const signInSuccess = async () => {
  const isNoPower = await initBackEndControlRoutes();
  if (isNoPower) {
    useMessage().warning('抱歉，您没有登录权限');
    Session.clear();
  } else {
    // 初始化登录成功时间问候语
    let currentTimeInfo = formatAxis(new Date());
    if (route.query?.redirect) {
      router.push({
        path: <string>route.query?.redirect,
        query: Object.keys(<string>route.query?.params).length > 0 ? JSON.parse(<string>route.query?.params) : '',
      });
    } else {
      router.push('/');
    }
    // 登录成功提示
    const signInText = t('signInText');
    useMessage().success(`${currentTimeInfo}，${signInText}`);
    // 添加 loading，防止第一次进入界面时出现短暂空白
    NextLoading.start();
  }
};

// 页面加载时
onMounted(() => {
  NextLoading.done();
});

// 改变背景色
const changeBackgroundColor = (index) =>{

  const gradientInfo = {
    0: 'radial-gradient(circle, rgba(255, 255, 255, 0.2), rgba(127, 181, 233, 0.2))',
    1: 'radial-gradient(circle, rgba(255, 255, 255, 0.2), rgba(102, 81, 63, 0.2))',
    2: 'radial-gradient(circle, rgba(255, 255, 255, 0.2), rgba(140, 139, 133, 0.2))',
    3: 'radial-gradient(circle, rgba(255, 255, 255, 0.2), rgba(114, 103, 97, 0.2)',
    4: 'radial-gradient(circle, rgba(255, 255, 255, 0.2), rgba(151, 113, 80, 0.2))',
    5: 'radial-gradient(circle, rgba(255, 255, 255, 0.2), rgba(178, 174, 171, 0.2))',
  };
  const logBox = document.getElementsByClassName('logBox');
  logBox[0].style.background  = gradientInfo[index];

}
</script>
<style scoped>
.select-none{
 /* background-color: #7bb2e6;*/
  background-image: url("/@/assets/login/loginBg.jpg");
  background-repeat: no-repeat;
  background-size: cover;
  position: relative
}

/*:deep(.el-input__wrapper){
  color: #ffffff;
  background-color: transparent; !* 完全透明 *!

}
:deep(.el-input__inner){
  color: #ffffff;
  background-color: transparent !important;
}
:deep(.login-msg){
!*color: #ffffff;*!
}*/
.login-container{
  grid-template-columns: 5fr 2fr; /* 第一列占 3 份，第二列占 1 份 */
  grid-gap:5rem
}
.semibold-icon{
  margin: 5px 8px 0 12px;
  width: 60px;
  height: 35px;
}
.Elegant{
  color:#CDD0D6;
  font-size: 13px;
  text-align: center;
  margin-bottom: 25px;
}
</style>
